package community.peers.hundreds;

import android.net.Uri;
import android.webkit.WebView;
import android.content.Intent;
import android.webkit.WebViewClient;

/**
 * Created by vaeringjar on 7/4/15.
 */
public class HundredsSandbox extends WebViewClient {

    public final static String PROTOCOL_HTTP = "http://";
    public final static String DOMAIN_INTERNET = "peers.community";


    public final static String PROTOCOL_FILE = "file:///";
    public final static String DOMAIN_SANDBOX = "android_asset/root/index.html";
    public final static String URI_INTERNET = PROTOCOL_HTTP + DOMAIN_INTERNET;
    public final static String URI_SANDBOX = PROTOCOL_FILE + DOMAIN_SANDBOX;

    @Override
    public boolean shouldOverrideUrlLoading(WebView webView, String url) {
        if(Uri.parse(url).getHost().endsWith(DOMAIN_INTERNET)) {
            return false;
        }
        else if(Uri.parse(url).getHost().length() == 0) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        webView.getContext().startActivity(intent);
        return true;
    }
}
